# Maintainer: Sven-Hendrik Haase <svenstaro@archlinux.org>
# Contributor: Daenyth <Daenyth+Arch [AT] gmail [DOT] com>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: rabyte <rabyte__gmail>

pkgname=supertuxkart
pkgver=1.4
pkgrel=5
pkgdesc='Kart racing game featuring Tux and his friends'
arch=('loong64' 'x86_64')
url='https://supertuxkart.net'
license=('GPL3')
depends=('openal' 'libvorbis' 'freetype2' 'harfbuzz' 'curl' 'bluez-libs'
         'sqlite' 'libjpeg-turbo' 'libpng' 'hicolor-icon-theme' 'sdl2' 'shaderc')
makedepends=('cmake' 'setconf' 'ninja')
source=("https://github.com/supertuxkart/stk-code/releases/download/${pkgver}/SuperTuxKart-${pkgver}-src.tar.xz"
        "fix-missing-rotation.patch::https://github.com/supertuxkart/stk-code/commit/0c2b81ac1f9ff29f5012a98f530880b87f416337.patch"
        "$pkgname-$pkgver-fix-crash.patch::https://github.com/Benau/stk-code/commit/8544f19b59208ae93fc3db0cf41bd386c6aefbcb.patch")
sha512sums=('e88f3fb5ccdb38d0ef75e92d73b43c5cc7a1f6c76ac9502033df099a00d6dc3e86b2c5442b806237d2420c44ada7dd23a2c90ecf94785a44d2348c933770a5ab'
            '8719ab359c462cf3758c38351d7bae7b49e759cc97c053fd1cd07c354eb1732d52ed7a02b50f4499525cd9ea1d65b85ec18538d4bf7970f318768a9ad36fbd6f'
            'c0fdb3b6aef2f9c62eb23777232fea928b5400ec7228df4007933872d0e0a20f11849fee569f05908ab61ace6364bd1051584122f29d35f8ce2c24ce2619fed3')

prepare() {
  cd "$srcdir"/SuperTuxKart-${pkgver}-src
  patch -Np1 -i ../fix-missing-rotation.patch
  patch -Np1 -i ../$pkgname-$pkgver-fix-crash.patch
}

build() {
  cd "$srcdir"/SuperTuxKart-${pkgver}-src

  _fn="data/${pkgname}.desktop"
  setconf "$_fn" Exec "$pkgname"
  setconf "$_fn" TryExec "$pkgname"
  setconf "$_fn" Icon "$pkgname"

  cmake . \
    -Bbuild \
    -GNinja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DBUILD_RECORDER=0

  ninja -C build
}

package() {
  cd "$srcdir"/SuperTuxKart-${pkgver}-src

  DESTDIR="$pkgdir" ninja -C build install

  # Why is this even in here?
  rm -r "$pkgdir"/usr/lib
  rm -r "$pkgdir"/usr/include
}

# vim:set ts=2 sw=2 et:
